/**
 * Created by pc126 on 2016/9/7.
 */
import { Component, OnInit } from '@angular/core';
import { LiveService } from './../shared/index';


@Component({
  selector:'live-list',
  templateUrl: 'app/live/live-list/live-list.component.html'
})
export class LiveListComponent implements OnInit{

  origin_data = [];

  liveCover_origin = [];
  liveTimeLine_origin = [];
  liveTimeLine = [];
  //博主uid
  liveKing_uid = "";
  liveKing_show = false;
   onScrollUp () {
    	console.log('scrolled 2up!!');
        //  alert(3)
    }

  constructor(public liveAPI:LiveService){

    liveAPI.getLiveCover(function(data){
      this.liveCover_origin = data.data;
      this.liveKing_uid = this.liveCover_origin.uid;
      console.info("livecover",this.liveCover_origin);
    }.bind(this));
    liveAPI.getLiveList(function(data){
      this.liveTimeLine_origin = data.data.liveElements;
      this.liveTimeLine = this.fromPostData(this.liveTimeLine_origin);
      console.info("livelist",this.liveTimeLine);
    }.bind(this))
  }
  ngOnInit() {
console.log("init live list11");
  }
  fromPostData(data){
    var result = [];
    var current = 0;
    var currentIndex = 0;
    while ( current < data.length ){
      // result.push([data[current]]);
      result.push({
        me:data[current].uid == this.liveKing_uid,
        // nickName:data[current].nickName,
        // createTime:data[current].createTime,
        // avatar:data[current].avatar,
        content:[data[current]]
      });
      while (current+1<data.length) {
        if( data[current].uid === data[current+1].uid){
          result[currentIndex].content.push(data[current+1]);
          current +=1;
        }else{
          currentIndex +=1;
          break;
        }
      }
      current +=1;
    }
    return result;
  }


}

